﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;


namespace SDFL.Utilities
{
    public class Mailer
    {
        private SmtpClient _smtpClient;
        private MailMessage _mailMess;        

        public string MailSubject
        {
            get;
            set;
        }

        public virtual string MailBody
        {
            get;
            set;
        }

        public Mailer(string mailFrom, string[] mailTo, string mailSubject, string mailBody)
        {
            LogManager.WriteEntry(EntryType.Standard, "Generating Mail...");

            _smtpClient = new SmtpClient("smtphost");
            _smtpClient.UseDefaultCredentials = true;

            _mailMess = new MailMessage()
            {
                Priority = MailPriority.Normal,
                IsBodyHtml = true,
                From = new MailAddress(mailFrom),
                Subject = mailSubject,
                Body = mailBody
            };

            foreach (string mailToAddr in mailTo)
            {
                _mailMess.To.Add(mailToAddr.Trim());
            } 
        }

        public void Send()
        { 
            LogManager.WriteEntry(EntryType.Standard, "Send Mail...");
            _smtpClient.Send(_mailMess);
            LogManager.WriteEntry(EntryType.Standard, "Send Success");
        }   
    }
}
